/*
 * ALWVApp.java
 */

package alwv;

import alwv.database.DerbyConnection;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;


/**
 * The main class of the application.
 */
public class ALWVApp extends SingleFrameApplication {
    private static Connection connection;
    private static String dblocation;
    private static String backuplocation;
    private static int daysbetweenbackups;
    /**
     * At startup create and show the main frame of the application.
     */
    @Override protected void startup() {
        show(new ALWVView(this));
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of ALWVApp
     */
    public static ALWVApp getApplication() {
        return Application.getInstance(ALWVApp.class);
        
        
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        launch(ALWVApp.class, args);
        startConnection();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(alwv.ALWVApp.class).getContext().getResourceMap(ALWVAboutBox.class);
        
        dblocation = resourceMap.getString("database.location");
        backuplocation = resourceMap.getString("database.backupslocation");
        daysbetweenbackups = Integer.parseInt(resourceMap.getString("database.daysbetweenbackups"));
    }
    
    public static void startConnection() {
        DerbyConnection dc = new DerbyConnection();
        dc.createConnection();
        connection = dc.getConnection();
    }
    
    public Connection getConnection() {
        return connection;
    }
    
    public String getDbLocation() {
        return dblocation;
    }
    
    public String getBackupLocation() {
        return backuplocation;
    }
    
    public void disconnect() {
        try {
            connection.close();
        } catch (SQLException ex) {
            Logger.getLogger(ALWVApp.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public int getDaysBetweenBackups() {
        return daysbetweenbackups;
    }
}
